using System;
using System.Collections;
using PetShop.Infrastructure.Exceptions;


namespace PetShop.Domain.Model
{

	
	[Serializable]
	public class Order {

      
		private int _OrderId;
        private DateTime _OrderDate;
        private Account _User;
        private decimal _OrderTotal;
		private CreditCardInfo _CreditCard;
		private AddressInfo _BillingAddress;
		private AddressInfo _ShippingAddress;
        private IList _LineItems;

       
		
		public Order(){
         
             _LineItems= new ArrayList();
          
        }
 

      
        public virtual int OrderId
        {
			get { return _OrderId; }
            set { _OrderId = value; }
			
		}

		public DateTime OrderDate {
            get { return _OrderDate; }
            set { _OrderDate = value; }
		}

        public Account User
        {
			get { return _User; }
			set { _User = value; }
		}

		public CreditCardInfo CreditCard {
			get { return _CreditCard; }
			set { _CreditCard = value; }
		}

		public AddressInfo BillingAddress {
			get { return _BillingAddress; }
			set { _BillingAddress = value; }
		}

		public AddressInfo ShippingAddress {
			get { return _ShippingAddress; }
			set { _ShippingAddress = value; }
		}

		public decimal OrderTotal {
			get { return _OrderTotal; }
			set { _OrderTotal = value; }
		}

		public IList LineItems {
			get { return _LineItems; }
			set { _LineItems = value; }
		}

        public void AddLineItemInfo(ItemEntity item, int qty)
        {
           //Line Number
            int lineNum = _LineItems.Count + 1;
            LineItemEntity lineItem = new LineItemEntity(qty, item, this);
            lineItem.LineNum = lineNum;
            _LineItems.Add(lineItem);
        }

    

        public void AddLineItemInfo(LineItemEntity item)
        {
            _LineItems.Add(item);
        }


        public void Validate()
        {

            //verify order
            if (this._LineItems.Count == 0)
            {
                throw new BusinessException("ORD001", "An order with No order items is not valid");
            }
        }

     



	}
}